package com.taoyuan.container.controller;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.taoyuan.common.log.annotation.Log;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.taoyuan.common.core.controller.BaseController;
import com.taoyuan.common.core.domain.AjaxResult;
import com.taoyuan.common.enums.BusinessType;
import com.taoyuan.container.domain.Gpu;
import com.taoyuan.container.service.IGpuService;
import com.taoyuan.common.utils.poi.ExcelUtil;
import com.taoyuan.common.core.page.TableDataInfo;

/**
 * GUP信息Controller
 *
 * @author taoyuan
 * @date 2023-07-02
 */
@RestController
@RequestMapping("/container/gpu")
public class GpuController extends BaseController {
    @Autowired
    private IGpuService gpuService;

    /**
     * 查询GUP信息列表
     */
    @PreAuthorize("@ss.hasPermi('container:gpu:list')")
    @GetMapping("/list")
    public TableDataInfo list(Gpu gpu) {
        startPage();
        List<Gpu> list = gpuService.selectGpuList(gpu);
        return getDataTable(list);
    }

    /**
     * 导出GUP信息列表
     */
    @PreAuthorize("@ss.hasPermi('container:gpu:export')")
    @Log(title = "GUP信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gpu gpu) {
        List<Gpu> list = gpuService.selectGpuList(gpu);
        ExcelUtil<Gpu> util = new ExcelUtil<Gpu>(Gpu.class);
        util.exportExcel(response, list, "GUP信息数据");
    }

    /**
     * 获取GUP信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('container:gpu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(gpuService.getById(id));
    }

    /**
     * 新增GUP信息
     */
    @PreAuthorize("@ss.hasPermi('container:gpu:add')")
    @Log(title = "GUP信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gpu gpu) {
        return toAjax(gpuService.save(gpu));
    }

    /**
     * 修改GUP信息
     */
    @PreAuthorize("@ss.hasPermi('container:gpu:edit')")
    @Log(title = "GUP信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gpu gpu) {
        return toAjax(gpuService.updateById(gpu));
    }

    /**
     * 删除GUP信息
     */
    @PreAuthorize("@ss.hasPermi('container:gpu:remove')")
    @Log(title = "GUP信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(gpuService.removeByIds(Arrays.asList(ids)));
    }
}
